/*
 * @Author: zhoujinlong 765637726@qq.com
 * @Date: 2024-02-26 09:08:40
 * @LastEditors: zhoujinlong 765637726@qq.com
 * @LastEditTime: 2024-04-11 11:34:23
 * @FilePath: \pingxi\src\main.ts
 */
/*
 *                        .::::.
 *                      .::::::::.
 *                     :::::::::::
 *                  ..:::::::::::'
 *               '::::::::::::'
 *                 .::::::::::
 *            '::::::::::::::..
 *                 ..::::::::::::.
 *               ``::::::::::::::::
 *                ::::``:::::::::'        .:::.
 *               ::::'   ':::::'       .::::::::.
 *             .::::'      ::::     .:::::::'::::.
 *            .:::'       :::::  .:::::::::' ':::::.
 *           .::'        :::::.:::::::::'      ':::::.
 *          .::'         ::::::::::::::'         ``::::.
 *      ...:::           ::::::::::::'              ``::.
 *     ````':.          ':::::::::'                  ::::..
 *                        '.:::::'                    ':'````..
 */

/*
 *  ┌───┐   ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┐
 *  │Esc│   │ F1│ F2│ F3│ F4│ │ F5│ F6│ F7│ F8│ │ F9│F10│F11│F12│ │P/S│S L│P/B│  ┌┐    ┌┐    ┌┐
 *  └───┘   └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┘  └┘    └┘    └┘
 *  ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐ ┌───┬───┬───┐ ┌───┬───┬───┬───┐
 *  │~ `│! 1│@ 2│# 3│$ 4│% 5│^ 6│& 7│* 8│( 9│) 0│_ -│+ =│ BacSp │ │Ins│Hom│PUp│ │N L│ / │ * │ - │
 *  ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤ ├───┼───┼───┤ ├───┼───┼───┼───┤
 *  │ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │{ [│} ]│ | \ │ │Del│End│PDn│ │ 7 │ 8 │ 9 │   │
 *  ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤ └───┴───┴───┘ ├───┼───┼───┤ + │
 *  │ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │: ;│" '│ Enter  │               │ 4 │ 5 │ 6 │   │
 *  ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤     ┌───┐     ├───┼───┼───┼───┤
 *  │ Shift  │ Z │ X │ C │ V │ B │ N │ M │< ,│> .│? /│  Shift   │     │ ↑ │     │ 1 │ 2 │ 3 │   │
 *  ├─────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ ├───┴───┼───┤ E││
 *  │ Ctrl│    │Alt │         Space         │ Alt│    │    │Ctrl│ │ ← │ ↓ │ → │ │   0   │ . │←─┘│
 *  └─────┴────┴────┴───────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ └───────┴───┴───┘
 */

import { createApp, ref } from "vue";
import "./style.css";
import App from "./App.vue";
import { createPinia } from "pinia";
import router from "./router";
import { createPersistedState } from "pinia-persistedstate-plugin";
import "./assets/scss/index.scss";
import Layui from "@layui/layui-vue";
import "@layui/layui-vue/lib/index.css";
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import VueSign from 'vue-esign'
import zhCn from "element-plus/dist/locale/zh-cn.mjs";
import "./tools/rem";

import { useCounterStore } from "@/current";
import { storeToRefs } from "pinia"; // cnpm i pinia --save  2.1.3

const app = createApp(App);

app.use(ElementPlus, {
  locale: zhCn,
});
const pinia = createPinia();
pinia.use(createPersistedState());

app.use(router);
app.use(pinia);
app.use(Layui);

app.use(ElementPlus);
app.use(VueSign)
app.mount("#app");

const store = useCounterStore();
const { nowMenuBtnArrKeys } = storeToRefs(store); //  数据

console.log(nowMenuBtnArrKeys.value);

app.directive("permissions", (el, binding) => {
  // 权限列表
  const keysArr = nowMenuBtnArrKeys.value || [];
  const { value } = binding;

  let shouldDisplay = false; // 默认不显示

  // 判断是否是数组
  if (Array.isArray(value)) {
    // 数组都满足才会显示
    shouldDisplay = value.every(val => keysArr.includes(val));
  } else {
    // 如果绑定的值不是数组，检查单个权限是否存在
    shouldDisplay = keysArr.includes(value);
  }

  if (!shouldDisplay) {
    // 如果不满足显示条件，移除元素
    el.parentElement?.removeChild(el);
  }
});